package context.util;

import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.LinkedList;
import org.lwjgl.BufferUtils;

public class Data
{
    
    private static Data singleton = new Data();
    
    public static Data get()
    {
        return Data.singleton;
    }
    
    private Data()
    {
    }
    
    
    /** Concatenates the list of Strings into one String with line breaks added between elements in the list. */
    public String concatenate(LinkedList<String> aLines)
    {
        StringBuilder fullSrc = new StringBuilder();
        while (!aLines.isEmpty())
        {
            fullSrc.append(aLines.removeFirst());
            fullSrc.append("\n");
        }
        return fullSrc.toString();
    }
    
    public ByteBuffer reserveDataByte(int aSize)
    {
        ByteBuffer data = BufferUtils.createByteBuffer(aSize);
        return data;
    }
    
    public IntBuffer reserveDataInt(int aSize)
    {
        IntBuffer data = BufferUtils.createIntBuffer(aSize);
        return data;
    }
    
    public FloatBuffer reserveDataFloat(int aSize)
    {
        FloatBuffer data = BufferUtils.createFloatBuffer(aSize);
        return data;
    }
    
    public ByteBuffer asByteBuffer(byte[] aData)
    {
        ByteBuffer data = Data.get().reserveDataByte(aData.length);
        data.put(aData);
        data.flip();
        return data;
    }
    
    public FloatBuffer asFloatBuffer(float[] aData)
    {
        FloatBuffer data = Data.get().reserveDataFloat(aData.length);
        data.put(aData);
        data.flip();
        return data;
    }
    
    public FloatBuffer asFloatBuffer(double[] aData)
    {
        float[] fData = new float[aData.length];
        for (int i = 0; i < aData.length; i++)
        {
            fData[i] = (float) aData[i];
        }
        return this.asFloatBuffer(fData);
    }
    
}
